package com.liao.app2.ui;

import androidx.appcompat.app.AppCompatActivity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.liao.app2.R;
import com.liao.app2.ui.bean.User;
import com.liao.app2.ui.db.UserDB;
import com.liao.examine.ItemListviewLayoutAdapter;

import java.util.ArrayList;

public class Main2Activity extends AppCompatActivity {

    ListView listView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        listView = findViewById(R.id.listView);
        UserDB userDB = new UserDB(this, "users", 1);
        SharedPreferences sp = getSharedPreferences("config", MODE_PRIVATE);
        boolean isUpdate = sp.getBoolean("isUpdate", false);
        ArrayList<User> allUser;
        if (isUpdate) {
            allUser = userDB.findAllUser1(userDB.getReadableDatabase());
        } else {
            allUser = userDB.findAllUser(userDB.getReadableDatabase());
        }
        ItemListviewLayoutAdapter adapter = new ItemListviewLayoutAdapter(this, allUser);
        listView.setAdapter(adapter);
    }
}
